package com.x.erp.dao;

import com.x.erp.model.Company;
import com.x.framework.dao.BaseDao;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class CompanyDao extends BaseDao{
    public static final String selectCompanyListSql = "SELECT T1.* FROM ERP_COMPANY T1, BASE_CITY T2 WHERE T1.CITY_ID = T2.CITY_ID ";
    public List<Company> selectCompanyList(Company company) throws Exception {
        StringBuilder sb = new StringBuilder(selectCompanyListSql);
        List<Object> params = new ArrayList<Object>();
        if(this.isString(company.getCompanyId())){
            sb.append("AND T1.COMPANY_ID = ? ");
            params.add(company.getCompanyId());
        }
        if(this.isString(company.getCompanyParentId())){
            sb.append("AND T1.COMPANY_PARENT_ID = ? ");
            params.add(company.getCompanyParentId());
        }
        if(this.isString(company.getCompanyCode())){
            sb.append("AND T1.COMPANY_CODE LIKE ? ");
            params.add(company.getCompanyCode() + "%");
        }
        if(this.isString(company.getCompanyName())){
            sb.append("AND T1.COMPANY_NAME = ? ");
            params.add(company.getCompanyName());
        }
        if(this.isString(company.getCompanyMobile())){
            sb.append("AND T1.COMPANY_MOBILE = ? ");
            params.add(company.getCompanyMobile());
        }
        if(this.isString(company.getCityId())){
            sb.append("AND T1.CITY_ID = ? ");
            params.add(company.getCityId());
        }
        if(this.isString(company.getProvinceId())){
            sb.append("AND T1.PROVINCE_ID = ? ");
            params.add(company.getProvinceId());
        }
        return this.queryForList(sb.toString(), Company.class, params);
    }
}
